﻿namespace ScriptEase
{
    public static class WebResourceType
    {
        public const int Webpage = 1;
        public const int StyleSheetCss = 2;
        public const int Script = 3;
        public const int Data = 4;
        public const int ImagePng = 5;
        public const int ImageJpg = 6;
        public const int ImageGif = 7;
        public const int Silverlight = 8;
        public const int StylesheetXsl = 9;
        public const int Icon = 10;
    }

    public class WebResourceDescriptor
    {
        public WebResourceDescriptor(int typeNo, string[] extensions)
        {
            this.TypeNo = typeNo;
            this.FileExtenstions = extensions;
        }



        /// <summary>
        /// Gets the type no.
        /// </summary>
        public int TypeNo { get; private set; }

        /// <summary>
        /// Gets the file extenstions. Element 0 is used as the default extension.
        /// </summary>
        public string[] FileExtenstions { get; private set; }
    }


    public static class WebResourceHelper
    {
        private static readonly WebResourceDescriptor[] _values;



        static WebResourceHelper()
        {
            _values = new WebResourceDescriptor[]
            {
                new WebResourceDescriptor(WebResourceType.Webpage, new string[] {".html", ".htm"}),
                new WebResourceDescriptor(WebResourceType.StyleSheetCss, new string[] {".css"}),
                new WebResourceDescriptor(WebResourceType.Script, new string[] {".js"}),
                new WebResourceDescriptor(WebResourceType.Data, new string[] {".xml"}),
                new WebResourceDescriptor(WebResourceType.ImagePng, new string[] {".png"}),
                new WebResourceDescriptor(WebResourceType.ImageJpg, new string[] {".jpg"}),
                new WebResourceDescriptor(WebResourceType.ImageGif, new string[] {".gif"}),
                new WebResourceDescriptor(WebResourceType.Silverlight, new string[] {".xap"}),
                new WebResourceDescriptor(WebResourceType.StylesheetXsl, new string[] {".xslt", ".xsl"}),
                new WebResourceDescriptor(WebResourceType.Icon, new string[] {".ico"})
            };
        }



        public static int GetTypeValue(this WebResource webResource)
        {
            return webResource.WebResourceType.Value;
        }



        public static WebResourceDescriptor GetDesc(this WebResource webResource)
        {
            return _values[webResource.WebResourceType.Value - 1];
        }
    }
}